<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">


      <el-form-item label="接收者ID" prop="receiverId">
        <el-input v-model="queryParams.receiverId" placeholder="接收者用户ID" />
      </el-form-item>
      <el-form-item label="发起转账ID" prop="userId">
        <el-input v-model="queryParams.transferUserId" placeholder="发起转账用户ID" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" show-summary sum-text="总金额" :data="list" element-loading-text="Loading" border fit
      highlight-current-row :summary-method="getSum">
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="转账单号" align="center" prop="orderNo" />
      <el-table-column label="转账人" align="center" prop="username">
        <template slot-scope="scope">
          {{ scope.row.username }}&nbsp;&nbsp;&nbsp;&nbsp;({{ scope.row.userId }})
        </template>
      </el-table-column>

      <el-table-column label="被转账人	" align="center" prop="receiverName">
        <template slot-scope="scope">
          {{ scope.row.receiverName }}&nbsp;&nbsp;&nbsp;&nbsp;({{ scope.row.receiverId }})
        </template>
      </el-table-column>
      <el-table-column label="转账金额" align="center" prop="amount" />

      <el-table-column label="转账时间	" align="center" prop="createTime" />
      <el-table-column label="转账人备注" align="center" prop="transferRemarks" />
      <el-table-column label="接收人备注" align="center" prop="receiverRemarks" />

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShowInfo(scope.row)">详情</el-button>

        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <ShowInfo ref="showInfo" />
  </div>
</template>

<script>
import { listByUser } from '@/api/table'
import ShowInfo from './showInfo.vue'
export default {
  components: {
    ShowInfo

  },
  data() {
    return {
      list: null,
      listLoading: false,
      total: 0,
      typeOptions: [
        { label: '虚拟货币', value: 'usdt' },
        { label: '人民币', value: 'rmb' }
      ],
      statusOptions: [
        { label: '申请中', value: 'applying' },
        { label: '审核通过', value: 'approved' },
        { label: '审核驳回', value: 'reject' }

      ],
      queryParams: {

        receiverId: '',
        pageNum: 1,
        pageSize: 10,
        transferUserId: '',

      }
    }
  },
  created() {
    // this.fetchData()
  },
  methods: {

    getSum(param) {
      const { columns, data } = param;
      console.log(param)
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '累计转账金额';
          return;
        }
        if (index === 1) {
          sums[index] = this.total  // 这里是总金额
          return;
        }
        if (index > 1) {
          sums[index] = ''
        }

      });

      return sums;
    },
    fetchData() {
      this.listLoading = true
      listByUser(this.queryParams).then(response => {
        this.list = response.data.records
        this.listLoading = false
        this.total = Number(response.message)
      })
    },
    handleShowInfo(e) {
      this.$refs.showInfo.show(e)
    },
    setStateTxt(index) {
      let str = ''
      switch (index) {
        case 'applying':
          str = '申请中'
          break
        case 'approved':
          str = '审核通过'
          break
        case 'reject':
          str = '审核驳回'
          break
      }
      return str
    },
    onSubmit() {
      this.queryParams.page = 1
      this.fetchData()
    },
    reset() {
      this.queryParams = {
        receiverId: '',
        pageNum: 1,
        pageSize: 10,
        transferUserId: '',
      }
      this.fetchData()
    },
    handleAdd() {
      this.$refs.add.show()
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleDel(e) {
      this.$confirm('此操作将删除公告, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        communityDelete(e).then(res => {
          this.fetchData()
          this.$message({
            type: 'success',
            message: '成功!'
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }
  }
}
</script>
<style>
/* 合并左侧列的样式 */
</style>
